import 'package:flutter/material.dart';

class DismissiblePage extends StatelessWidget {
  const DismissiblePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    var listTile = ["测试数据", "测试数据", "测试数据", "测试数据", "测试数据", "测试数据", "测试数据", "测试数据", "测试数据", "测试数据", "测试数据", "测试数据", "测试数据", "测试数据", "测试数据", "测试数据", "测试数据", "测试数据", "测试数据", "测试数据", "测试数据", "测试数据", "测试数据", "测试数据", "测试数据", "测试数据", "测试数据"];
    return Scaffold(
      appBar: AppBar(),
      body: Container(
        alignment: Alignment.center,
        child: ListView(
          children: listTile.map((e) {
            return Dismissible(
              key: ValueKey(e),
              background: Container(
                color: Colors.green,
                alignment: Alignment(-0.9, 0),
                child: Icon(Icons.check, color: Colors.white),
              ),
              secondaryBackground: Container(
                alignment: Alignment(0.9, 0),
                child: Icon(Icons.close, color: Colors.white),
                color: Colors.red,
              ),
              child: ListTile(
                subtitle: Text(e),
                title: Text(e),
              ),
              onDismissed: (d) {
                listTile.remove(e);
              },
              confirmDismiss: (e) async {
                if (e == DismissDirection.endToStart) {
                  return true;
                } else {
                  return false;
                }
              },
            );
          }).toList(),
        ),
      ),
    );
  }
}
